package per.ethan.javase.reflection;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author Ethan
 * @date 2020/04/27 09:33
 */
public class Demo1 {

    public static void main(String[] args) {
        try {
            Class<?> clazz = Class.forName("per.ethan.javase.reflection.User");
            // Class<User> userClass = User.class;

            // Class<?> aClass = new User().getClass();

            User user = (User) clazz.newInstance();

            Method[] methods = clazz.getMethods();
            for (Method method : methods) {
                System.out.print(method.getName() + "\t");
            }

            System.out.println();

            Field[] declaredFields = clazz.getDeclaredFields();
            for (Field declaredField : declaredFields) {
                System.out.print(declaredField.getType() + "\t");

                Annotation[] declaredAnnotations = declaredField.getDeclaredAnnotations();
                for (Annotation annotation : declaredAnnotations) {
                    System.out.println(annotation.annotationType());
                }
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }

}
